(function (vc, vm) {
    vc.extends({
        data: {
            editLabelInfo: {
                labelId: '',
                labelName: '',
                domains: [],
                domain: '',
                labelType: 'C'
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editLabel', 'openEditLabelModal', function (_params) {
                $that.refreshEditLabelInfo();
                vc.getDict('s_label', "domain", function (_data) {
                    $that.editLabelInfo.domains = _data;
                });
                $('#editLabelModel').modal('show');
                vc.copyObject(_params, $that.editLabelInfo);
                $that.editLabelInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            editLabelValidate: function () {
                return vc.validate.validate({
                    editLabelInfo: $that.editLabelInfo
                }, {
                    'editLabelInfo.labelName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "标签名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "标签名称不能超过30位"
                        },
                    ],
                    'editLabelInfo.domain': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "域不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "域格式错误"
                        },
                    ],
                    'editLabelInfo.labelType': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "标签类型不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "12",
                            errInfo: "标签类型格式错误"
                        },
                    ],
                    'editLabelInfo.labelId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "标签ID不能为空"
                        }
                    ]
                });
            },
            editLabel: function () {
                if (!$that.editLabelValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.http.apiPost(
                    '/label/updateLabel',
                    JSON.stringify($that.editLabelInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editLabelModel').modal('hide');
                            vc.emit('labelManage', 'listLabel', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditLabelInfo: function () {
                $that.editLabelInfo = {
                    labelId: '',
                    labelName: '',
                    domains: [],
                    domain: '',
                    labelType: 'C'
                }
            }
        }
    });
})(window.vc, window.vc.component);
